﻿@model BBICMS.Application.InputModels.Products.ProductPhotoIM
@{
    ViewBag.Title = "产品图片";
    ViewBag.PageTitle = ViewBag.Title + "_产品_内容";
}

@section Header{
<link href="~/plugins/SigFinder/SigFinder.min.css" rel="stylesheet" />
<link href="~/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <style>
        .img-box figcaption{
            display:block;padding:8px 15px;text-align:center;background-color:#f7f7f7;
        }
    </style>
}



<div class="main-content">
    <div class="panel panel-default">
        <header class="panel-heading">
            <h3 class="panel-title"><span class="glyphicon glyphicon-picture"></span> 组图管理</h3>
        </header>


        <div class="panel-body">
            <!-- gallery wrapper -->
             
                <div class="row">
                    @foreach (var photo in (IEnumerable<ProductPhoto>)ViewBag.Photos)
                    {
                    <!-- single image -->
                    <div class="col-xs-3 item-container">
                        <figure class="img-box">                            
                            <img class="img-responsive" alt="picture" src="@photo.ImageUrl" />
                            <figcaption>
                                <a href="@Url.Action("DeletePhoto", new {Id = photo.Id})" class="btn btn-sm btn-danger delete-item" title="删除">
                                <i class="glyphicon glyphicon-trash"></i> 删除
                                </a>
                            </figcaption>
                        </figure>
                    </div>

                    }
                </div>
          
        </div>
    </div>
    <div class="panel panel-default">
        <header class="panel-heading">
            <h3 class="panel-title"><span class="glyphicon glyphicon-upload"></span>  组图上传</h3>
        </header>


        <div class="panel-body">
            <!-- end gallery wrapper -->

            <div class="no-gallery">  

                @using (Ajax.BeginForm("AddPhoto", Model, new AjaxOptions()
                {

                LoadingElementId = "saving",
                LoadingElementDuration = 2000,
                //   Confirm = "Are you sure you want to save this User?"
                OnSuccess = "updateSuccess"
                }, new { @class = "form-horizontal", role = "form" }))
                {

                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true)

                @Html.HiddenFor(model => model.ProductId)

                <div class="form-group">
                    @Html.LabelFor(model => model.ImageURL, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.ImageURL, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ImageURL, ViewData).Watermark })
                            <span class="input-group-btn">
                                <button class="btn btn-default" id="btnThumbnail" type="button">浏览…</button>
                            </span>
                        </div><!-- /input-group -->
                        <span class="help-block">图片尺寸：1140x478 像素</span>
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.ImageURL)
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Importance, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Importance, new { @class = "form-control", type = "number", placeholder = ModelMetadata.FromLambdaExpression(x => x.Importance, ViewData).Watermark })
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.Importance)
                    </div>

                </div>


                <div class="form-group">
                    <div class="col-sm-offset-2 col-md-10">
                        <button type="submit" class="btn btn-primary" id="btnSave"><i class="fa fa-save fa-fw"></i>  @Buttons.Update </button>
                        <a href="@Url.Action("Index","Product")" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> @Buttons.Back</a>
                    </div>
                </div>

                }



            </div>
            <!-- end blank state -->
        </div>


    </div>
</div>
<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

@Html.Action("PopuFinder", "File")
@section Footer {
  @Scripts.Render("~/bundles/jqueryvalWithBootstrap")
<script src="/Plugins/webuploader/webuploader.min.js"></script>
<script src="/Plugins/SigFinder/FileManager.js"></script>

    <script>
        function SetThumbnail() {
            var fileUrl = $("#fileList .item.active").attr("data-file");
            $('#ImageURL').val(fileUrl);
            $('#fileManagerModal').modal('hide');
        }

        function onBeginSave() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin");
        }
        function onCompleteSave() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save");
        }
        function updateSuccess(data) {
            var title = '@ViewBag.Title';
            Common.ShowBox(data.Status, data.Message, title);
           
            if (data.Status===1) {           
                setTimeout(function() {
                    location.reload();
                }, 1000);
            }


        }



        $(function () {
            $("#btnThumbnail").on("click", function () {
                $('#fileManagerModal').modal();
                $("#selectImage").unbind('click');
                $("#selectImage").bind("click", function () {
                    SetThumbnail();
                });
            });

        

            //删除数据
            $('.delete-item').click(function (e) {
                e.preventDefault();
                var url = $(this).attr('href'), that = $(this), title = '@string.Format("删除{0}", EntityNames.Category)';

                bootbox.setLocale("zh_CN");

                bootbox.confirm("是否确定删除该项？", function (result) {
                    if (result) {
                        Common.DeleteItem(url, title, that);
                    }
                });
            });

        });
    </script>
}
